package cate.game.play.skill.passive.fairy;

import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.proce.round.RoundCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 效果1：普通攻击会优先攻击敌方后排目标  （脚本里写死）
 * 效果2：【潜行】状态下额外获得30%暴击和30%暴击伤害伤害，闪避提升到40%。（强化buff）
 * 效果3：“闪袭”新增效果:技能无视速度优先出手。
 *           【潜行】强化下，技能系数增加15%，并且击杀后80%概率对敌方全体附加【颤栗】
 */
public class 猫屎咖啡灵器PH extends PassiveHandler {


	private int 闪袭原型;

	private String 强化标签;

	private double 系数;

	private int 概率;

	private int buff;

	//闪袭原型=？？&强化标签=??&系数=1500&概率=8000&buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		闪袭原型 = args.getInt("闪袭原型", 0);
		强化标签 = args.get("强化标签");
		系数 = args.getDouble("系数", 0d);
		概率 = args.getInt("概率", 0);
		buff = args.getInt("buff", 0);
	}

	@Override
	public void onPreSelectByCD(RoundCtx round, Skill selectSkill) {
		if (selectSkill.cfg.row.protoId == 闪袭原型) {
			skill.owner.status.setIgnSpeedSort(true);
			skill.owner.status.setTurnSkill(selectSkill);
		}
	}

	@Override
	public void beforeSelectTargets(MoveCtx move, Skill skill) {
		if (skill.cfg.isType(GDSkill.Type.ATTACK)) {
			for (Fighter target : move.getTeamVS().getEnemyTeam(skill.owner.team).getFightersAlive()) {
				if (target.getPos() > 3) {
					skill.param.addTopPriorityPid(target.getPid());
				}
			}
		}
	}

	@Override
	public void beforeSkillSettleAsActor(SkillActionCtx action, SkillEffect effect, Fighter target) {
		if(!action.getSkill().cfg.containTag(强化标签)){
			return;
		}
		effect.addHpCfgByCoeff(系数);
	}

	@Override
	public void onSkillDone(SkillActionCtx action) {
		if (!action.getSkill().cfg.containTag(强化标签)) {
			return;
		}
		if (action.getStat().getTotalKill(skill.owner.getPid()) <= 0) {
			return;
		}
		if (!XT.chance(概率)) {
			return;
		}
		for (Fighter target : action.getTeamVs().getEnemyTeam(skill.owner.team).getFightersAlive()) {
			target.buff.tryAddByTid(action, skill.owner, buff);
		}
	}
}
